/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

Ext.QuickTips.init();
var _pageSize = 20;
var now = new Date();
var fieldName = ['id', 'deviceNo', 'modelId', 'adminAreaCode', 'terminalNo', 'installSite', 'mobileNo', 'uniqueCode', 'ip', 'port', 'pointId', 'pointName', 'runTime',
    'checkTime', 'expireTime', 'status', 'note', 'updateTime', 'createTime', 'orgCode', 'model', 'commTypeName', 'manufactoryName', 'shortName', 'produceTime', 'channel',
    'zbm', 'protocolName', 'protocolCode'];
var fieldLabel = ['ID', '装置编码', '终端型号ID', '区域码', '终端地址', '安装地点', '手机号码', '唯一码', 'IP地址', '端口', '监测点ID', '监测点名称', '投运日期', '检验日期',
    '有效期', '备注', '状态', '更新日期', '创建日期', '机构编码', '型号', '通信方式', '生产厂家', '所属单位', '出厂日期', '通道', '组编码', '协议名称', '协议编码'];

var saveServlet = '../../servlet/system/DeviceSave';
var loadServlet = '../../servlet/system/DeviceLoad';
var deleteServlet = '../../servlet/system/DeviceDel';
var dbtable = 't_device';
var theme = '装置';

var _title = currentOrgName + theme + '管理';

var modelStore = new Ext.data.JsonStore({
    url: '../../servlet/common/SimpleInfoLoad',
    baseParams: {id: 'id', name: 'model', tableName: 't_model'},
    autoLoad: true,
    root: 'data',
    fields: ['id', 'model']
});

var modelCombo = {
    name: 'model',
    xtype: 'combo',
    store: modelStore,
    id: 'ModelCombo',
    displayField: 'model',
    valueField: 'id',
    hiddenName: 'modelId',
    //typeAhead: true,
    autoSelect: true,
    //editable: true,
    //minChars:1,
    //autoLoad:true,
    mode: 'remote',
    forceSelection: true,
    allowBlank: false,
    blankText: '不允许为空',
    triggerAction: 'all',
    fieldLabel: '型号',
    emptyText: '请选择型号...',
    selectOnFocus: true,
    listeners: {
        select: function(combo, record, index) {

            if (record.get('model') === 'DT3') {
                modelDT3();
            } else if (record.get('model') === 'DT4-2') {
                modelDT4();
            } else {

            }
        }
    }

};

function modelDT3() {
    Ext.getCmp('AdminAreaCode').disable();
    Ext.getCmp('AdminAreaCode').hide();
    Ext.getCmp('zbm').disable();
    Ext.getCmp('zbm').hide();
    Ext.getCmp('Ip').disable();
    Ext.getCmp('Ip').hide();
    Ext.getCmp('UniqueCode').enable();
    Ext.getCmp('UniqueCode').show();
}

function modelDT4() {
    Ext.getCmp('UniqueCode').disable();
    Ext.getCmp('UniqueCode').hide();
    Ext.getCmp('AdminAreaCode').enable();
    Ext.getCmp('AdminAreaCode').show();
    Ext.getCmp('zbm').enable();
    Ext.getCmp('zbm').show();
    Ext.getCmp('Ip').enable();
    Ext.getCmp('Ip').show();
}

function modelNew() {
    Ext.getCmp('AdminAreaCode').disable();
    Ext.getCmp('AdminAreaCode').hide();
    Ext.getCmp('zbm').disable();
    Ext.getCmp('zbm').hide();
    Ext.getCmp('Ip').disable();
    Ext.getCmp('Ip').hide();
    Ext.getCmp('UniqueCode').disable();
    Ext.getCmp('UniqueCode').hide();

    Ext.getCmp('DeviceNo').setValue("");
    Ext.getCmp('ModelCombo').setValue("");
    Ext.getCmp('AdminAreaCode').setValue("");
    Ext.getCmp('terminalNo').setValue("");
    Ext.getCmp('zbm').setValue("");
    Ext.getCmp('installSite').setValue("");
    Ext.getCmp('MobileNo').setValue("");
    Ext.getCmp('UniqueCode').setValue("");
    Ext.getCmp('Ip').setValue("");
    Ext.getCmp('Port').setValue("");
    Ext.getCmp('Channel').setValue("");
    Ext.getCmp('RunTime').setValue("");
    Ext.getCmp('ProduceTime').setValue("");
    Ext.getCmp('CheckTime').setValue("");
    Ext.getCmp('ExpireTime').setValue("");
    Ext.getCmp('Note').setValue("");
}

var comProtocolStore = new Ext.data.JsonStore({
    url: '../../servlet/common/SimpleInfoLoad',
    baseParams: {id: 'protocolCode', name: 'protocolName', tableName: 't_commProtocol'},
    autoLoad: true,
    root: 'data',
    fields: ['protocolCode', 'protocolName']
});

var comProtocolCombo = {
    name: 'protocolName',
    xtype: 'combo',
    store: comProtocolStore,
    id: 'ComProtocolCombo',
    displayField: 'protocolName',
    valueField: 'protocolCode',
    hiddenName: 'protocolCode',
    autoSelect: true,
    mode: 'remote',
    forceSelection: true,
    allowBlank: false,
    blankText: '不允许为空',
    triggerAction: 'all',
    fieldLabel: '协议名称',
    emptyText: '请选择协议名称...',
    selectOnFocus: true
};

var inputForm = new Ext.FormPanel(
        {
            xtype: 'form',
            id: 'input-form',
            bodyStyle: 'padding:15px;background:transparent',
            frame: true,
            border: false,
            url: saveServlet,
            items: [{
                    name: 'id',
                    xtype: 'textfield',
                    fieldLabel: 'ID',
                    hidden: true
                }
                , {
                    name: 'deviceNo',
                    id: 'DeviceNo',
                    xtype: 'textfield',
                    fieldLabel: '装置编码',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写',
                    maxLength: 25,
                    maxLengthText: '不能多于25个字符,1个汉字占用2个字符'
                }
                , modelCombo,
                comProtocolCombo,
                {
                    name: 'adminAreaCode',
                    id: 'AdminAreaCode',
                    xtype: 'textfield',
                    fieldLabel: '区域码',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写',
                    maxLength: 5,
                    maxLengthText: '不能多于5个字符,1个汉字占用2个字符'
                }, {
                    name: 'terminalNo',
                    id: 'terminalNo',
                    xtype: 'textfield',
                    fieldLabel: '终端地址',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写',
                    maxLength: 10,
                    maxLengthText: '不能多于10个字符,1个汉字占用2个字符'
                }, {
                    name: 'zbm',
                    id: 'zbm',
                    xtype: 'textfield',
                    fieldLabel: '组编码',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写'
                }, {
                    name: 'installSite',
                    id: 'installSite',
                    xtype: 'textfield',
                    fieldLabel: '安装地点',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写',
                    maxLength: 50,
                    maxLengthText: '不能多于50个字符,1个汉字占用2个字符'
                }, {
                    name: 'mobileNo',
                    id: 'MobileNo',
                    xtype: 'textfield',
                    fieldLabel: '手机号码',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写',
                    regex: /^([0-9]+)$/,
                    regexText: "手机号码只能输入数字",
                    maxLength: 20,
                    maxLengthText: '不能多于20个字符,1个汉字占用2个字符'
                }, {
                    name: 'uniqueCode',
                    id: 'UniqueCode',
                    xtype: 'textfield',
                    fieldLabel: '唯一码',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写',
                    maxLength: 25,
                    maxLengthText: '不能多于25个字符,1个汉字占用2个字符'
                }, {
                    name: 'ip',
                    id: 'Ip',
                    xtype: 'textfield',
                    fieldLabel: 'IP地址',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写',
                    maxLength: 20,
                    maxLengthText: '不能多于20个字符,1个汉字占用2个字符'
                }, {
                    name: 'port',
                    id: 'Port',
                    xtype: 'numberfield',
                    fieldLabel: '端口',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写数字',
                    maxValue: 9999,
                    minValue: 1,
                    maxText: '端口在1-9999之间',
                    minText: '端口在1-9999之间'
                }, {
                    name: 'channel',
                    id: 'Channel',
                    xtype: 'textfield',
                    fieldLabel: '通道',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写',
                    maxLength: 1,
                    maxLengthText: '不能多于1个字符,1个汉字占用2个字符'
                }, {
                    name: 'runTime',
                    id: 'RunTime',
                    xtype: 'datefield',
                    fieldLabel: '投运日期',
                    format: 'Y-m-d H:i:s',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写'
                }, {
                    name: 'produceTime',
                    id: 'ProduceTime',
                    xtype: 'datefield',
                    fieldLabel: '出厂日期',
                    format: 'Y-m-d H:i:s',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写'
                }, {
                    name: 'checkTime',
                    id: 'CheckTime',
                    xtype: 'datefield',
                    fieldLabel: '校验日期',
                    format: 'Y-m-d H:i:s',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写'
                }, {
                    name: 'expireTime',
                    id: 'ExpireTime',
                    xtype: 'datefield',
                    fieldLabel: '有效期',
                    format: 'Y-m-d H:i:s',
                    width: 160,
                    allowBlank: false,
                    blankText: '必须填写'
                }, {
                    name: 'note',
                    id: 'Note',
                    xtype: 'textfield',
                    fieldLabel: '备注',
                    width: 160,
                    allowBlank: true,
                    maxLength: 25,
                    maxLengthText: '不能多于25个字符,1个汉字占用2个字符'
                }
            ],
            buttons: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function() {
                        var submitConfig = {
                            success: function(form, action) {
                                store.reload();
                                //parent.Ext.getCmp('OrganTree').getRootNode().reload();
                                win.hide();
                            },
                            failure: function(form, action) {
                                switch (action.failureType) {
                                    case Ext.form.Action.CONNECT_FAILURE:
                                        Ext.Msg.alert('提示', '网络连接失败');
                                        break;
                                    case Ext.form.Action.SERVER_INVALID:
                                        Ext.Msg.alert('提示', action.result.msg);
                                }
                            },
                            params: {}
                        };
                        var token1 = new Date().getTime();
                        submitConfig.params.token = token;
                        submitConfig.params.token1 = token1;
                        if (type === 1)
                            submitConfig.params.cmd = 'create';
                        else {
                            submitConfig.params.id = checkboxSel.getSelected().get("id");
                            submitConfig.params.cmd = 'update';
                        }
                        Ext.getCmp('input-form').getForm().submit(submitConfig);
                    }
                }, {
                    text: '取消',
                    handler: function() {
                        win.hide();
                    }
                }]
        }
);
var win = new Ext.Window({
    layout: 'form',
    modal: true,
    width: 340,
    autoHeight: true,
    closeAction: 'hide',
    items: [inputForm]
});
var type = 1;         //判断打开窗口是进行更新，还是新建。1-新建；2-修改
var updated = false;
function addnew() {
    type = 1;
    win.setTitle('增加' + theme);
    Ext.getCmp('input-form').getForm().reset();
    Ext.getCmp('RunTime').setValue(now);
    //Ext.getCmp('ProduceTime').setValue(now); 
    modelNew();
    win.show();
}

function update() {
    updated = true;
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("提示", "您还没有选择，需要选择一个记录才能修改");
    }
    else if (checkboxSel.getSelections().length > 1) {
        Ext.Msg.alert("提示", "您选择了多个记录，只能选择一个记录进行修改");
    }
    else {
        type = 2;
        Ext.getCmp('input-form').getForm().loadRecord(checkboxSel.getSelected());
        var temp = checkboxSel.getSelected().get('runTime');
        var r = Date.parseDate(temp, 'yy-m-d H:i:s.u', false);
        Ext.getCmp('RunTime').setValue(r);

        temp = checkboxSel.getSelected().get('produceTime');
        r = Date.parseDate(temp, 'yy-m-d H:i:s.u', false);
        Ext.getCmp('ProduceTime').setValue(r);

        temp = checkboxSel.getSelected().get('checkTime');
        r = Date.parseDate(temp, 'yy-m-d H:i:s.u', false);
        Ext.getCmp('CheckTime').setValue(r);

        temp = checkboxSel.getSelected().get('expireTime');
        r = Date.parseDate(temp, 'yy-m-d H:i:s.u', false);
        Ext.getCmp('ExpireTime').setValue(r);

        win.setTitle('修改' + theme);

        temp = checkboxSel.getSelected().get('model');

        if (temp === 'DT3') {
            modelDT3();
        } else if (temp === 'DT4-2') {
            modelDT4();
        } else {

        }

        win.show();
        //Ext.getDom('win-title').innerHTML='修改监控设备信息';
    }
}

function remove() {
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("修改" + theme, "您还没有选择，需要先选择才能删除");
    }
    else {

        var records = checkboxSel.getSelections();
        var jsonData = "";
        for (var i = 0, len = records.length; i < len; i++) {
            var ss = records[i].get("id"); //这里为Grid数据源的Id列
            var pointId = records[i].get("pointId");
            if (pointId != 0) {
                Ext.Msg.alert("系统消息", "已绑定监测点的装置不能删除");
                return;
            }
            if (i === 0)
                jsonData = jsonData + ss;
            else
                jsonData = jsonData + "," + ss;
        }
        Ext.MessageBox.confirm('提示', '确实要删除所选的记录吗?', function(btn) {
            if (btn === 'yes') {
                var token1 = new Date().getTime();
                var conn = new Ext.data.Connection();
                conn.request({
                    url: deleteServlet, //提交的删除地址
                    params: {token:token,token1:token1,ids: jsonData},
                    method: 'post',
                    scope: this,
                    callback: function(options, success, response) {
                        if (success) {
                            var messager = Ext.decode(response.responseText);
                            if (messager.success) {
                                Ext.MessageBox.alert("提示", "所选记录成功删除！");
                                store.reload(); //重新load数据   	
                                //              parent.Ext.getCmp('ManuFactoryTree').getNodeById(currenManuFactoryCode).reload();
                            }
                            else {
                                Ext.Msg.alert('提示', messager.msg);
                            }

                        } else {
                            Ext.MessageBox.alert("提示", "所选记录删除失败！");
                        }
                    }
                });
            }
        });
    }
}

var checkForm = new Ext.FormPanel(
        {
            xtype: 'form',
            id: 'CheckForm',
            bodyStyle: 'padding:15px;background:transparent',
            frame: true,
            border: false,
            url: saveServlet,
            items: [{
                    name: fieldName[0],
                    xtype: 'textfield',
                    fieldLabel: fieldLabel[0],
                    hidden: true
                }
                , {
                    name: 'deviceNo',
                    xtype: 'textfield',
                    fieldLabel: '装置编码',
                    allowBlank: false,
                    readOnly: true
                },
                {
                    name: 'model',
                    xtype: 'textfield',
                    readOnly: true,
                    fieldLabel: "型号",
                    allowBlank: false
                },
                {
                    name: 'protocolName',
                    xtype: 'textfield',
                    readOnly: true,
                    fieldLabel: "协议名称",
                    allowBlank: false
                },
                {
                    name: 'manufactoryName',
                    xtype: 'textfield',
                    readOnly: true,
                    fieldLabel: "生产厂家",
                    allowBlank: false
                },
                {
                    name: 'pointName',
                    xtype: 'textfield',
                    id: 'PointName',
                    readOnly: true,
                    fieldLabel: "监测点",
                    allowBlank: false
                }, {
                    name: 'checkTime',
                    xtype: 'datefield',
                    fieldLabel: '上次检验日期',
                    format: 'Y-m-d',
                    hidden: true
                }, {
                    name: 'expireTime',
                    xtype: 'datefield',
                    fieldLabel: '上次有效期',
                    format: 'Y-m-d',
                    hidden: true
                }, {
                    name: 'checkTimeNew',
                    xtype: 'datefield',
                    fieldLabel: '新检验日期',
                    format: 'Y-m-d h:i:s',
                    value: new Date()
                }, {
                    name: 'expireTimeNew',
                    xtype: 'datefield',
                    fieldLabel: '新有效期',
                    format: 'Y-m-d h:i:s',
                    value: new Date()
                }
            ],
            buttons: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function() {
                        var submitConfig = {
                            success: function(form, action) {
                                store.reload();
                                winCheck.hide();
                            },
                            failure: function(form, action) {
                                switch (action.failureType) {
                                    case Ext.form.Action.CONNECT_FAILURE:
                                        Ext.Msg.alert('提示', '网络连接失败');
                                        break;
                                    case Ext.form.Action.SERVER_INVALID:
                                        Ext.Msg.alert('提示', action.result.msg);
                                }
                            },
                            params: {}
                        };
                        var token1 = new Date().getTime();
                        submitConfig.params.token = token;
                        submitConfig.params.token1 = token1;
                        submitConfig.params.id = checkboxSel.getSelected().get("id");
                        submitConfig.params.cmd = 'check';
                        Ext.getCmp('CheckForm').getForm().submit(submitConfig);
                    }
                }, {
                    text: '取消',
                    handler: function() {
                        winCheck.hide();
                    }
                }]
        }
);
var winCheck = new Ext.Window({
    title: '装置校验',
    layout: 'form',
    width: 340,
    autoHeight: true,
    closeAction: 'hide',
    items: [checkForm]
});

var startForm = new Ext.FormPanel(
        {
            xtype: 'form',
            id: 'StartForm',
            bodyStyle: 'padding:15px;background:transparent',
            frame: true,
            border: false,
            url: saveServlet,
            items: [{
                    name: fieldName[0],
                    xtype: 'textfield',
                    fieldLabel: fieldLabel[0],
                    hidden: true
                }
                , {
                    name: 'deviceNo',
                    xtype: 'textfield',
                    fieldLabel: '装置编码',
                    allowBlank: false,
                    readOnly: true
                },
                {
                    name: 'model',
                    xtype: 'textfield',
                    readOnly: true,
                    fieldLabel: "型号",
                    allowBlank: false
                },
                {
                    name: 'manufactoryName',
                    xtype: 'textfield',
                    readOnly: true,
                    fieldLabel: "生产厂家",
                    allowBlank: false
                },
                {
                    name: 'pointName',
                    xtype: 'textfield',
                    id: 'PointName',
                    readOnly: true,
                    fieldLabel: "监测点",
                    allowBlank: false
                }, {
                    name: 'checkTime',
                    xtype: 'datefield',
                    fieldLabel: '上次检验日期',
                    format: 'Y-m-d',
                    hidden: true
                }, {
                    name: 'expireTime',
                    xtype: 'datefield',
                    fieldLabel: '上次有效期',
                    format: 'Y-m-d',
                    hidden: true
                }, {
                    name: 'checkTimeNew',
                    xtype: 'datefield',
                    fieldLabel: '新检验日期',
                    format: 'Y-m-d h:i:s',
                    value: new Date()
                }, {
                    name: 'expireTimeNew',
                    xtype: 'datefield',
                    fieldLabel: '新有效期',
                    format: 'Y-m-d h:i:s',
                    value: new Date()
                }
            ],
            buttons: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function() {
                        var submitConfig = {
                            success: function(form, action) {
                                store.reload();
                                winCheck.hide();
                            },
                            failure: function(form, action) {
                                switch (action.failureType) {
                                    case Ext.form.Action.CONNECT_FAILURE:
                                        Ext.Msg.alert('提示', '网络连接失败');
                                        break;
                                    case Ext.form.Action.SERVER_INVALID:
                                        Ext.Msg.alert('提示', action.result.msg);
                                }
                            },
                            params: {}
                        };
                        var token1 = new Date().getTime();
                        submitConfig.params.token = token;
                        submitConfig.params.token1 = token1;
                        submitConfig.params.id = checkboxSel.getSelected().get("id");
                        submitConfig.params.cmd = 'check';
                        Ext.getCmp('CheckForm').getForm().submit(submitConfig);
                    }
                }, {
                    text: '取消',
                    handler: function() {
                        winCheck.hide();
                    }
                }]
        }
);

function check() {
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择设备");
        return;
    }
    var r = checkboxSel.getSelected();
    Ext.getCmp('CheckForm').getForm().loadRecord(r);
    var pointName = r.get('pointName');
    if (pointName === null || pointName === '')
        Ext.getCmp('PointName').setValue('未绑定');
    winCheck.show();
}


var checkboxSel = new Ext.grid.CheckboxSelectionModel();
var store;
function buildWindow() {
    store = new Ext.data.JsonStore({
        url: loadServlet,
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName
        , baseParams: {start: 0, limit: _pageSize}
        , autoLoad: true
    });

    var grid = new Ext.grid.GridPanel({
        title: _title,
        store: store,
        sm: checkboxSel,
        columns: [
            checkboxSel,
            {header: 'ID', sortable: true, dataIndex: 'id', hidden: true},
            {header: "状态", dataIndex: 'pointId', width: 40,
                renderer: function(v, metaData, record, rowIndex, colIndex, store) {
                    var value = parseInt(v);
                    var imageName;
                    if (value > 0) {
                        imageName = 'image.png';
                        return "<image src='" + basePath + "image/icon/" + imageName + "'/>";
                    } else
                        return "";
                }
            },
            {header: '装置编码', width: 100, sortable: true, dataIndex: 'deviceNo'},
            {header: '终端型号ID', width: 80, sortable: true, dataIndex: 'modelId', hidden: true},
            {header: '型号', width: 80, sortable: true, dataIndex: 'model'},
            {header: '区域码', width: 80, sortable: true, dataIndex: 'adminAreaCode'},
            {header: '终端地址', width: 80, sortable: true, dataIndex: 'terminalNo'},
            {header: '组编码', width: 80, sortable: true, dataIndex: 'zbm'},
            {header: '安装地点', width: 150, sortable: true, dataIndex: 'installSite'},
            {header: '手机号码', width: 100, sortable: true, dataIndex: 'mobileNo'},
            {header: '唯一码', width: 100, sortable: true, dataIndex: 'uniqueCode'},
            {header: 'IP地址', width: 110, sortable: true, dataIndex: 'ip'},
            {header: '端口', width: 60, sortable: true, dataIndex: 'port'},
            {header: '通道', width: 60, sortable: true, dataIndex: 'channel'},
            {header: '通信类型', width: 80, sortable: true, dataIndex: 'commTypeName'},
            {header: '协议名称', width: 80, sortable: true, dataIndex: 'protocolName'},
            {header: '公司名称', width: 120, sortable: true, dataIndex: 'manufactoryName'},
            {header: '监测点ID', width: 60, sortable: true, dataIndex: 'pointId', hidden: true},
            {header: '监测点名称', width: 150, sortable: true, dataIndex: 'pointName'},
            {header: '投运日期', width: 80, sortable: true, dataIndex: 'runTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '出厂日期', width: 80, sortable: true, dataIndex: 'produceTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '检验日期', width: 80, sortable: true, dataIndex: 'checkTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '有效期', width: 80, sortable: true, dataIndex: 'expireTime', xtype: 'datecolumn', format: 'Y-m-d'},
            {header: '启用', width: 80, sortable: true, dataIndex: fieldName[15], renderer: function(value, metaData, record, rowIndex, colIndex, store) {
                    if (value % 10 === 1) {
                        return '启用';
                    } else if (value % 10 === 2) {
                        return '绑定';
                    } else {
                        return '未启用';
                    }
                }
            },
            {header: '备注', width: 80, sortable: true, dataIndex: 'note'}
        ],
        //autoExpandColumn: fieldName[2],
        //renderTo: Ext.getBody(),
        //width: 780,
        //height: 590,
        loadMask: true,
        tbar: new Ext.Toolbar([
            {text: '新增', iconCls: 'icon-add', handler: addnew},
            '-',
            {text: '修改', iconCls: 'icon-edit', handler: update},
            '-',
            {text: '删除', iconCls: 'icon-delete', handler: remove},
            {text: '校验', iconCls: 'icon-check', handler: check, hidden: true}
        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: "目前没有" + theme + '信息'
        })
    });
    //grid.el.center();
    //store.load({params: {start: 0, limit: _pageSize}});



    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
            grid
        ]
    });
}
Ext.onReady(buildWindow);
